package com.staff.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.util.AJAXResultMessage;
import com.common.util.ExtjsPageable;
import com.staff.entity.StaffReward;
import com.staff.entity.dto.StaffRewardQueryDTO;
import com.staff.service.IStaffRewardService;
import com.syslog.aop.SystemServiceLog;

@Controller
@RequestMapping("/staffReward")
public class StaffRewardController {
	@Autowired
	private IStaffRewardService staffRewardService;
	
	@SystemServiceLog("新建或修改员工奖惩信息")
	@RequestMapping("/saveOrUpdate")
	public @ResponseBody AJAXResultMessage saveOrUpdate(StaffRewardQueryDTO staffContractQueryDTO) 
	{
		try {
			
			return staffRewardService.saveOrUpdate(staffContractQueryDTO);
		} catch (Exception e) {
			return new AJAXResultMessage(false,"操作失败");
		}
	}
	@SystemServiceLog("删除员工奖惩信息")
	@RequestMapping("/delete")
	public @ResponseBody AJAXResultMessage delete(@RequestParam Long id) 
	{
		try {
			StaffReward staffContract =  staffRewardService.findOne(id);
			if(null!=staffContract) {
				staffRewardService.delete(staffContract);
			}
			return new AJAXResultMessage(true,"操作成功！");
		} catch (Exception e) {
			return new AJAXResultMessage(false,"操作失败！");
		}
	}
	@SystemServiceLog("批量删除员工奖惩信息")
	@RequestMapping("/deletes")
	public @ResponseBody AJAXResultMessage deleteStaffs(@RequestParam Long[] ids) 
	{
		try {
			List<Long> idLists = Arrays.asList(ids);
			if(null!=idLists) {
				staffRewardService.delete(idLists);
			}
			return new AJAXResultMessage(true,"操作成功！");
		} catch (Exception e) {
			return new AJAXResultMessage(false,"操作失败！");
		}
	}
	@SystemServiceLog("查找员工奖惩信息")
	@RequestMapping("/findOne")
	public @ResponseBody StaffReward findOne(@RequestParam Long id) 
	{
		StaffReward staffContract =  staffRewardService.findOne(id);
		
		return staffContract;
	}
	
	@SystemServiceLog("查找所有员工奖惩信息")
	@RequestMapping("/findAll")
	public @ResponseBody List<StaffReward> findAll() 
	{
		 List<StaffReward> lists =  staffRewardService.findAll();
		
		return lists;
	}
	//
	//分页查询（需要DTO）
	@SystemServiceLog("分页查找所有员工奖惩信息")
	@RequestMapping("/findPage")
	public @ResponseBody Page<StaffRewardQueryDTO> findPage(StaffRewardQueryDTO userQueryDto,ExtjsPageable pageable){
		Page<StaffRewardQueryDTO> page = staffRewardService.findAll(StaffRewardQueryDTO.getSpecification(userQueryDto),pageable.getPageable());
		return page;
	}
}
